package me.huangxiang.design_pattern.observer;

public class CurrentConditionsDisplay implements Observer, DisplayElement {
    private float temp;
    private float humidity;
    private float pressure;
    private Subject weatherData;

    @Override
    public void display() {
        System.out.println(String.format("当前温度： %.1f 湿度： %.1f 气压： %.1f", this.temp, this.humidity, this.pressure) );
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temp = temp;
        this.humidity = humidity;
        this.pressure = pressure;
        display();
    }

    public CurrentConditionsDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        this.weatherData.registerObserver(this);
    }
}
